home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cc / dist / tree.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-03  |  57.8 KB  |  2,203 lines

  1. /* Language-indepednent node constructors for parse phase of GNU compiler.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file contains the low level primitives for operating on tree nodes,
  22.    including allocation, list operations, interning of identifiers,
  23.    construction of data type nodes and statement nodes,
  24.    and construction of type conversion nodes.  It also contains
  25.    tables index by tree code that describe how to take apart
  26.    nodes of that code.
  27.  
  28.    It is intended to be language-independent, but occasionally
  29.    calls language-dependent routines defined (for C) in typecheck.c.
  30.  
  31.    The low-level allocation routines oballoc and permalloc
  32.    are used also for allocating many other kinds of objects
  33.    by all passes of the compiler.  */
  34.  
  35. #include "config.h"
  36. #include <stdio.h>
  37. #include "tree.h"
  38. #include "obstack.h"
  39. #include "gvarargs.h"
  40. #include "flags.h"
  41.  
  42. #define obstack_chunk_alloc xmalloc
  43. #define obstack_chunk_free free
  44.  
  45. extern int xmalloc ();
  46. extern void free ();
  47.  
  48. /* Tree nodes of permanent duration are allocated in this obstack.
  49.    They are the identifier nodes, and everything outside of
  50.    the bodies and parameters of function definitions.  */
  51.  
  52. struct obstack permanent_obstack;
  53.  
  54. /* The initial RTL, and all ..._TYPE nodes, in a function
  55.    are allocated in this obstack.  Usually they are freed at the
  56.    end of the function, but if the function is inline they are saved.  */
  57.  
  58. struct obstack maybepermanent_obstack;
  59.  
  60. /* The contents of the current function definition are allocated
  61.    in this obstack, and all are freed at the end of the function.  */
  62.  
  63. struct obstack temporary_obstack;
  64.  
  65. /* The tree nodes of an expression are allocated
  66.    in this obstack, and all are freed at the end of the expression.  */
  67.  
  68. struct obstack momentary_obstack;
  69.  
  70. /* This points at either permanent_obstack or maybepermanent_obstack.  */
  71.  
  72. struct obstack *saveable_obstack;
  73.  
  74. /* This is same as saveable_obstack during parse and expansion phase;
  75.    it points to temporary_obstack during optimization.
  76.    This is the obstack to be used for creating rtl objects.  */
  77.  
  78. struct obstack *rtl_obstack;
  79.  
  80. /* This points at either permanent_obstack or temporary_obstack.  */
  81.  
  82. struct obstack *current_obstack;
  83.  
  84. /* This points at either permanent_obstack or temporary_obstack
  85.    or momentary_obstack.  */
  86.  
  87. struct obstack *expression_obstack;
  88.  
  89. /* Addresses of first objects in some obstacks.
  90.    This is for freeing their entire contents.  */
  91. char *maybepermanent_firstobj;
  92. char *temporary_firstobj;
  93. char *momentary_firstobj;
  94.  
  95. /* Nonzero means all ..._TYPE nodes should be allocated permanently.  */
  96.  
  97. int all_types_permanent;
  98.  
  99. /* Stack of places to restore the momentary obstack back to.  */
  100.    
  101. struct momentary_level
  102. {
  103.   /* Pointer back to previous such level.  */
  104.   struct momentary_level *prev;
  105.   /* First object allocated within this level.  */
  106.   char *base;
  107.   /* Value of expression_obstack saved at entry to this level.  */
  108.   struct obstack *obstack;
  109. };
  110.  
  111. struct momentary_level *momentary_stack;
  112.  
  113. /* Table indexed by tree code giving a string containing a character
  114.    classifying the tree code.  Possibilities are
  115.    t, d, s, c, r and e.  See tree.def for details.  */
  116.  
  117. #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
  118.  
  119. char *tree_code_type[] = {
  120. #include "tree.def"
  121. };
  122. #undef DEFTREECODE
  123.  
  124. /* Table indexed by tree code giving number of expression
  125.    operands beyond the fixed part of the node structure.
  126.    Not used for types or decls.  */
  127.  
  128. #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
  129.  
  130. int tree_code_length[] = {
  131. #include "tree.def"
  132. };
  133. #undef DEFTREECODE
  134.  
  135. /* Counter for assigning unique ids to all tree nodes.  */
  136.  
  137. int tree_node_counter = 0;
  138.  
  139. /* Hash table for uniquizing IDENTIFIER_NODEs by name.  */
  140.  
  141. #define MAX_HASH_TABLE 1009
  142. static tree hash_table[MAX_HASH_TABLE];    /* id hash buckets */
  143.  
  144. /* 0 while creating built-in identifiers.  */
  145. static int do_identifier_warnings;
  146.  
  147. /* Init data for node creation, at the beginning of compilation.  */
  148.  
  149. void
  150. init_tree ()
  151. {
  152.   obstack_init (&permanent_obstack);
  153.  
  154.   obstack_init (&temporary_obstack);
  155.   temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
  156.   obstack_init (&momentary_obstack);
  157.   momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0);
  158.   obstack_init (&maybepermanent_obstack);
  159.   maybepermanent_firstobj
  160.     = (char *) obstack_alloc (&maybepermanent_obstack, 0);
  161.  
  162.   current_obstack = &permanent_obstack;
  163.   expression_obstack = &permanent_obstack;
  164.   rtl_obstack = saveable_obstack = &permanent_obstack;
  165.   tree_node_counter = 1;
  166.   bzero (hash_table, sizeof hash_table);
  167. }
  168.  
  169. /* Start allocating on the temporary (per function) obstack.
  170.    This is done in start_function before parsing the function body,
  171.    and before each initialization at top level, and to go back
  172.    to temporary allocation after doing end_temporary_allocation.  */
  173.  
  174. void
  175. temporary_allocation ()
  176. {
  177.   current_obstack = &temporary_obstack;
  178.   expression_obstack = &temporary_obstack;
  179.   rtl_obstack = saveable_obstack = &maybepermanent_obstack;
  180.   momentary_stack = 0;
  181. }
  182.  
  183. /* Start allocating on the permanent obstack but don't
  184.    free the temporary data.  After calling this, call
  185.    `permanent_allocation' to fully resume permanent allocation status.  */
  186.  
  187. void
  188. end_temporary_allocation ()
  189. {
  190.   current_obstack = &permanent_obstack;
  191.   expression_obstack = &permanent_obstack;
  192.   rtl_obstack = saveable_obstack = &permanent_obstack;
  193. }
  194.  
  195. /* Resume allocating on the temporary obstack, undoing
  196.    effects of `end_temporary_allocation'.  */
  197.  
  198. void
  199. resume_temporary_allocation ()
  200. {
  201.   current_obstack = &temporary_obstack;
  202.   expression_obstack = &temporary_obstack;
  203.   rtl_obstack = saveable_obstack = &maybepermanent_obstack;
  204. }
  205.  
  206. /* Nonzero if temporary allocation is currently in effect.
  207.    Zero if currently doing permanent allocation.  */
  208.  
  209. int
  210. allocation_temporary_p ()
  211. {
  212.   return current_obstack == &temporary_obstack;
  213. }
  214.  
  215. /* Go back to allocating on the permanent obstack
  216.    and free everything in the temporary obstack.
  217.    This is done in finish_function after fully compiling a function.  */
  218.  
  219. void
  220. permanent_allocation ()
  221. {
  222.   /* Free up previous temporary obstack data */
  223.   obstack_free (&temporary_obstack, temporary_firstobj);
  224.   obstack_free (&momentary_obstack, momentary_firstobj);
  225.   obstack_free (&maybepermanent_obstack, maybepermanent_firstobj);
  226.  
  227.   current_obstack = &permanent_obstack;
  228.   expression_obstack = &permanent_obstack;
  229.   rtl_obstack = saveable_obstack = &permanent_obstack;
  230. }
  231.  
  232. /* Save permanently everything on the maybepermanent_obstack.  */
  233.  
  234. void
  235. preserve_data ()
  236. {
  237.   maybepermanent_firstobj
  238.     = (char *) obstack_alloc (&maybepermanent_obstack, 0);
  239. }
  240.  
  241. /* Allocate SIZE bytes in the current obstack
  242.    and return a pointer to them.
  243.    In practice the current obstack is always the temporary one.  */
  244.  
  245. char *
  246. oballoc (size)
  247.      int size;
  248. {
  249.   return (char *) obstack_alloc (current_obstack, size);
  250. }
  251.  
  252. /* Free the object PTR in the current obstack
  253.    as well as everything allocated since PTR.
  254.    In practice the current obstack is always the temporary one.  */
  255.  
  256. void
  257. obfree (ptr)
  258.      char *ptr;
  259. {
  260.   obstack_free (current_obstack, ptr);
  261. }
  262.  
  263. /* Allocate SIZE bytes in the permanent obstack
  264.    and return a pointer to them.  */
  265.  
  266. char *
  267. permalloc (size)
  268.      long size;
  269. {
  270.   return (char *) obstack_alloc (&permanent_obstack, size);
  271. }
  272.  
  273. /* Allocate SIZE bytes in the saveable obstack
  274.    and return a pointer to them.  */
  275.  
  276. char *
  277. savealloc (size)
  278.      int size;
  279. {
  280.   return (char *) obstack_alloc (saveable_obstack, size);
  281. }
  282.  
  283. /* Start a level of momentary allocation.
  284.    In C, each compound statement has its own level
  285.    and that level is freed at the end of each statement.
  286.    All expression nodes are allocated in the momentary allocation level.  */
  287.  
  288. void
  289. push_momentary ()
  290. {
  291.   struct momentary_level *tem
  292.     = (struct momentary_level *) obstack_alloc (&momentary_obstack,
  293.                         sizeof (struct momentary_level));
  294.   tem->prev = momentary_stack;
  295.   tem->base = (char *) obstack_base (&momentary_obstack);
  296.   tem->obstack = expression_obstack;
  297.   momentary_stack = tem;
  298.   expression_obstack = &momentary_obstack;
  299. }
  300.  
  301. /* Free all the storage in the current momentary-allocation level.
  302.    In C, this happens at the end of each statement.  */
  303.  
  304. void
  305. clear_momentary ()
  306. {
  307.   obstack_free (&momentary_obstack, momentary_stack->base);
  308. }
  309.  
  310. /* Discard a level of momentary allocation.
  311.    In C, this happens at the end of each compound statement.
  312.    Restore the status of expression node allocation
  313.    that was in effect before this level was created.  */
  314.  
  315. void
  316. pop_momentary ()
  317. {
  318.   struct momentary_level *tem = momentary_stack;
  319.   momentary_stack = tem->prev;
  320.   obstack_free (&momentary_obstack, tem);
  321.   expression_obstack = tem->obstack;
  322. }
  323.  
  324. /* Call when starting to parse a declaration:
  325.    make expressions in the declaration last the length of the function.
  326.    Returns an argument that should be passed to resume_momentary later.  */
  327.  
  328. int
  329. suspend_momentary ()
  330. {
  331.   register int tem = expression_obstack == &momentary_obstack;
  332.   expression_obstack = saveable_obstack;
  333.   return tem;
  334. }
  335.  
  336. /* Call when finished parsing a declaration:
  337.    restore the treatment of node-allocation that was
  338.    in effect before the suspension.
  339.    YES should be the value previously returned by suspend_momentary.  */
  340.  
  341. void
  342. resume_momentary (yes)
  343.      int yes;
  344. {
  345.   if (yes)
  346.     expression_obstack = &momentary_obstack;
  347. }
  348.  
  349. /* Return a newly allocated node of code CODE.
  350.    Initialize the node's unique id and its TREE_PERMANENT flag.
  351.    For decl and type nodes, some other fields are initialized.
  352.    The rest of the node is initialized to zero.
  353.  
  354.    Achoo!  I got a code in the node.  */
  355.  
  356. tree
  357. make_node (code)
  358.      enum tree_code code;
  359. {
  360.   register tree t;
  361.   register int type = *tree_code_type[(int) code];
  362.   register int length;
  363.   register struct obstack *obstack = current_obstack;
  364.   register int i;
  365.  
  366.   switch (type)
  367.     {
  368.     case 'd':  /* A decl node */
  369.       length = sizeof (struct tree_decl);
  370.       /* All decls in an inline function need to be saved.  */
  371.       if (obstack != &permanent_obstack)
  372.     obstack = saveable_obstack;
  373.       /* PARM_DECLs always go on saveable_obstack, not permanent,
  374.      even though we may make them before the function turns
  375.      on temporary allocation.  */
  376.       else if (code == PARM_DECL)
  377.     obstack = &maybepermanent_obstack;
  378.       break;
  379.  
  380.     case 't':  /* a type node */
  381.       length = sizeof (struct tree_type);
  382.       /* All data types are put where we can preserve them if nec.  */
  383.       if (obstack != &permanent_obstack)
  384.     obstack = all_types_permanent ? &permanent_obstack : saveable_obstack;
  385.       break;
  386.  
  387.     case 's':  /* a stmt node */
  388.       length = sizeof (struct tree_common)
  389.     + 2 * sizeof (int)
  390.       + tree_code_length[(int) code] * sizeof (char *);
  391.       /* All stmts are put where we can preserve them if nec.  */
  392.       if (obstack != &permanent_obstack)
  393.     obstack = saveable_obstack;
  394.       break;
  395.  
  396.     case 'r':  /* a reference */
  397.     case 'e':  /* an expression */
  398.       obstack = expression_obstack;
  399.       length = sizeof (struct tree_exp)
  400.     + (tree_code_length[(int) code] - 1) * sizeof (char *);
  401.       break;
  402.  
  403.     case 'c':  /* a constant */
  404.       obstack = expression_obstack;
  405.       /* We can't use tree_code_length for this, since the number of words
  406.      is machine-dependent due to varying alignment of `double'.  */
  407.       if (code == REAL_CST)
  408.     {
  409.       length = sizeof (struct tree_real_cst);
  410.       break;
  411.     }
  412.  
  413.     case 'x':  /* something random, like an identifier.  */
  414.       length = sizeof (struct tree_common)
  415.     + tree_code_length[(int) code] * sizeof (char *);
  416.       /* Identifier nodes are always permanent since they are
  417.      unique in a compiler run.  */
  418.       if (code == IDENTIFIER_NODE) obstack = &permanent_obstack;
  419.     }
  420.  
  421.   t = (tree) obstack_alloc (obstack, length);
  422.  
  423.   TREE_UID (t) = tree_node_counter++;
  424.   TREE_TYPE (t) = 0;
  425.   TREE_CHAIN (t) = 0;
  426.   for (i = (length / sizeof (int)) - 1;
  427.        i >= sizeof (struct tree_common) / sizeof (int) - 1;
  428.        i--)
  429.     ((int *) t)[i] = 0;
  430.  
  431.   TREE_SET_CODE (t, code);
  432.   if (obstack == &permanent_obstack)
  433.     TREE_PERMANENT (t) = 1;
  434.  
  435.   if (type == 'd')
  436.     {
  437.       extern int lineno;
  438.  
  439.       DECL_ALIGN (t) = 1;
  440.       DECL_SIZE_UNIT (t) = 1;
  441.       DECL_VOFFSET_UNIT (t) = 1;
  442.       DECL_SOURCE_LINE (t) = lineno;
  443.       DECL_SOURCE_FILE (t) = input_filename;
  444.     }
  445.  
  446.   if (type == 't')
  447.     {
  448.       TYPE_ALIGN (t) = 1;
  449.       TYPE_SIZE_UNIT (t) = 1;
  450.       TYPE_MAIN_VARIANT (t) = t;
  451.     }
  452.  
  453.   if (type == 'c')
  454.     {
  455.       TREE_LITERAL (t) = 1;
  456.     }
  457.  
  458.   return t;
  459. }
  460.  
  461. /* Return a new node with the same contents as NODE
  462.    except that its TREE_CHAIN is zero and it has a fresh uid.  */
  463.  
  464. tree
  465. copy_node (node)
  466.      tree node;
  467. {
  468.   register tree t;
  469.   register enum tree_code code = TREE_CODE (node);
  470.   register int length;
  471.   register int i;
  472.  
  473.   switch (*tree_code_type[(int) code])
  474.     {
  475.     case 'd':  /* A decl node */
  476.       length = sizeof (struct tree_decl);
  477.       break;
  478.  
  479.     case 't':  /* a type node */
  480.       length = sizeof (struct tree_type);
  481.       break;
  482.  
  483.     case 's':
  484.       length = sizeof (struct tree_common)
  485.     + 2 * sizeof (int)
  486.       + tree_code_length[(int) code] * sizeof (char *);
  487.       break;
  488.  
  489.     case 'r':  /* a reference */
  490.     case 'e':  /* a expression */
  491.       length = sizeof (struct tree_exp)
  492.     + (tree_code_length[(int) code] - 1) * sizeof (char *);
  493.       break;
  494.  
  495.     case 'c':  /* a constant */
  496.       /* We can't use tree_code_length for this, since the number of words
  497.      is machine-dependent due to varying alignment of `double'.  */
  498.       if (code == REAL_CST)
  499.     {
  500.       length = sizeof (struct tree_real_cst);
  501.       break;
  502.     }
  503.  
  504.     case 'x':  /* something random, like an identifier.  */
  505.       length = sizeof (struct tree_common)
  506.     + tree_code_length[(int) code] * sizeof (char *);
  507.     }
  508.  
  509.   t = (tree) obstack_alloc (current_obstack, length);
  510.  
  511.   for (i = ((length + sizeof (int) - 1) / sizeof (int)) - 1;
  512.        i >= 0;
  513.        i--)
  514.     ((int *) t)[i] = ((int *) node)[i];
  515.  
  516.   TREE_UID (t) = tree_node_counter++;
  517.   TREE_CHAIN (t) = 0;
  518.  
  519.   TREE_PERMANENT (t) = (current_obstack == &permanent_obstack);
  520.  
  521.   return t;
  522. }
  523.  
  524. /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
  525.    For example, this can copy a list made of TREE_LIST nodes.  */
  526.  
  527. tree
  528. copy_list (list)
  529.      tree list;
  530. {
  531.   tree head;
  532.   register tree prev, next;
  533.  
  534.   if (list == 0)
  535.     return 0;
  536.  
  537.   head = prev = copy_node (list);
  538.   next = TREE_CHAIN (list);
  539.   while (next)
  540.     {
  541.       TREE_CHAIN (prev) = copy_node (next);
  542.       prev = TREE_CHAIN (prev);
  543.       next = TREE_CHAIN (next);
  544.     }
  545.   return head;
  546. }
  547.  
  548. #define HASHBITS 30
  549.  
  550. /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
  551.    If an identifier with that name has previously been referred to,
  552.    the same node is returned this time.  */
  553.  
  554. tree
  555. get_identifier (text)
  556.      register char *text;
  557. {
  558.   register int hi;
  559.   register int i;
  560.   register tree idp;
  561.   register int len, hash_len;
  562.  
  563.   /* Compute length of text in len.  */
  564.   for (len = 0; text[len]; len++);
  565.  
  566.   /* Decide how much of that length to hash on */
  567.   hash_len = len;
  568.   if (warn_id_clash && len > id_clash_len)
  569.     hash_len = id_clash_len;
  570.  
  571.   /* Compute hash code */
  572.   hi = hash_len;
  573.   for (i = 0; i < hash_len; i++)
  574.     hi = ((hi * 613) + (unsigned)(text[i]));
  575.  
  576.   hi &= (1 << HASHBITS) - 1;
  577.   hi %= MAX_HASH_TABLE;
  578.   
  579.   /* Search table for identifier */
  580.   for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
  581.     if (IDENTIFIER_LENGTH (idp) == len
  582.     && !strcmp (IDENTIFIER_POINTER (idp), text))
  583.       return idp;        /* <-- return if found */
  584.   
  585.   /* Not found; optionally warn about a similar identifier */
  586.   if (warn_id_clash && do_identifier_warnings && len > id_clash_len)
  587.     for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
  588.       if (!strncmp (IDENTIFIER_POINTER (idp), text, id_clash_len))
  589.     {
  590.       warning ("`%s' and `%s' identical in first n characters",
  591.            IDENTIFIER_POINTER (idp), text);
  592.       break;
  593.     }
  594.  
  595.   /* Not found, create one, add to chain */
  596.   idp = make_node (IDENTIFIER_NODE);
  597.   IDENTIFIER_LENGTH (idp) = len;
  598.  
  599.   IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len);
  600.  
  601.   TREE_CHAIN (idp) = hash_table[hi];
  602.   hash_table[hi] = idp;
  603.   return idp;            /* <-- return if created */
  604. }
  605.  
  606. /* Enable warnings on similar identifiers (if requested).
  607.    Done after the built-in identifiers are created.  */
  608.  
  609. void
  610. start_identifier_warnings ()
  611. {
  612.   do_identifier_warnings = 1;
  613. }
  614.  
  615. /* Record the size of an identifier node for the language in use.
  616.    This is called by the language-specific files.  */
  617.  
  618. void
  619. set_identifier_size (size)
  620.      int size;
  621. {
  622.   tree_code_length[(int) IDENTIFIER_NODE] = size;
  623. }
  624.  
  625. /* Return a newly constructed INTEGER_CST node whose constant value
  626.    is specified by the two ints LOW and HI.
  627.    The TREE_TYPE is set to `int'.  */
  628.  
  629. tree
  630. build_int_2 (low, hi)
  631.      int low, hi;
  632. {
  633.   register tree t = make_node (INTEGER_CST);
  634.   TREE_INT_CST_LOW (t) = low;
  635.   TREE_INT_CST_HIGH (t) = hi;
  636.   TREE_TYPE (t) = integer_type_node;
  637.   return t;
  638. }
  639.  
  640. /* Return a new REAL_CST node whose type is TYPE and value is D.  */
  641.  
  642. tree
  643. build_real (type, d)
  644.      tree type;
  645.      REAL_VALUE_TYPE d;
  646. {
  647.   tree v;
  648.  
  649.   /* Check for valid float value for this type on this target machine;
  650.      if not, can print error message and store a valid value in D.  */
  651. #ifdef CHECK_FLOAT_VALUE
  652.   CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
  653. #endif
  654.  
  655.   v = make_node (REAL_CST);
  656.   TREE_TYPE (v) = type;
  657.   TREE_REAL_CST (v) = d;
  658.   return v;
  659. }
  660.  
  661. /* Return a new REAL_CST node whose type is TYPE
  662.    and whose value is the integer value of the INTEGER_CST node I.  */
  663.  
  664. #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  665.  
  666. REAL_VALUE_TYPE
  667. real_value_from_int_cst (i)
  668.      tree i;
  669. {
  670.   REAL_VALUE_TYPE d;
  671. #ifdef REAL_ARITHMETIC
  672.   REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
  673. #else /* not REAL_ARITHMETIC */
  674.   if (TREE_INT_CST_HIGH (i) < 0)
  675.     {
  676.       d = (double) (~ TREE_INT_CST_HIGH (i));
  677.       d *= ((double) (1 << (HOST_BITS_PER_INT / 2))
  678.         * (double) (1 << (HOST_BITS_PER_INT / 2)));
  679.       d += (double) (unsigned) (~ TREE_INT_CST_LOW (i));
  680.       d = (- d - 1.0);
  681.     }
  682.   else
  683.     {
  684.       d = (double) TREE_INT_CST_HIGH (i);
  685.       d *= ((double) (1 << (HOST_BITS_PER_INT / 2))
  686.         * (double) (1 << (HOST_BITS_PER_INT / 2)));
  687.       d += (double) (unsigned) TREE_INT_CST_LOW (i);
  688.     }
  689. #endif /* not REAL_ARITHMETIC */
  690.   return d;
  691. }
  692.  
  693. /* This function can't be implemented if we can't do arithmetic
  694.    on the float representation.  */
  695.  
  696. tree
  697. build_real_from_int_cst (type, i)
  698.      tree type;
  699.      tree i;
  700. {
  701.   tree v;
  702.   REAL_VALUE_TYPE d;
  703.  
  704.   v = make_node (REAL_CST);
  705.   TREE_TYPE (v) = type;
  706.  
  707.   d = real_value_from_int_cst (i);
  708.   /* Check for valid float value for this type on this target machine;
  709.      if not, can print error message and store a valid value in D.  */
  710. #ifdef CHECK_FLOAT_VALUE
  711.   CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
  712. #endif
  713.  
  714.   TREE_REAL_CST (v) = d;
  715.   return v;
  716. }
  717.  
  718. #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
  719.  
  720. /* Return a newly constructed STRING_CST node whose value is
  721.    the LEN characters at STR.
  722.    The TREE_TYPE is not initialized.  */
  723.  
  724. tree
  725. build_string (len, str)
  726.      int len;
  727.      char *str;
  728. {
  729.   register tree s = make_node (STRING_CST);
  730.   TREE_STRING_LENGTH (s) = len;
  731.   TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len);
  732.   return s;
  733. }
  734.  
  735. /* Return a newly constructed COMPLEX_CST node whose value is
  736.    specified by the real and imaginary parts REAL and IMAG.
  737.    Both REAL and IMAG should be constant nodes.
  738.    The TREE_TYPE is not initialized.  */
  739.  
  740. tree
  741. build_complex (real, imag)
  742.      tree real, imag;
  743. {
  744.   register tree t = make_node (COMPLEX_CST);
  745.   TREE_REALPART (t) = real;
  746.   TREE_IMAGPART (t) = imag;
  747.   return t;
  748. }
  749.  
  750. /* Return 1 if EXPR is the integer constant zero.  */
  751.  
  752. int
  753. integer_zerop (expr)
  754.      tree expr;
  755. {
  756.   return (TREE_CODE (expr) == INTEGER_CST
  757.       && TREE_INT_CST_LOW (expr) == 0
  758.       && TREE_INT_CST_HIGH (expr) == 0);
  759. }
  760.  
  761. /* Return 1 if EXPR is the integer constant one.  */
  762.  
  763. int
  764. integer_onep (expr)
  765.      tree expr;
  766. {
  767.   return (TREE_CODE (expr) == INTEGER_CST
  768.       && TREE_INT_CST_LOW (expr) == 1
  769.       && TREE_INT_CST_HIGH (expr) == 0);
  770. }
  771.  
  772. /* Return 1 if EXPR is an integer containing all 1's
  773.    in as much precision as it contains.  */
  774.  
  775. int
  776. integer_all_onesp (expr)
  777.      tree expr;
  778. {
  779.   register int prec;
  780.   register int uns;
  781.  
  782.   if (TREE_CODE (expr) != INTEGER_CST)
  783.     return 0;
  784.  
  785.   uns = TREE_UNSIGNED (TREE_TYPE (expr));
  786.   if (!uns)
  787.     return TREE_INT_CST_LOW (expr) == -1 && TREE_INT_CST_HIGH (expr) == -1;
  788.  
  789.   prec = TYPE_PRECISION (TREE_TYPE (expr));
  790.   if (prec >= HOST_BITS_PER_INT)
  791.     return TREE_INT_CST_LOW (expr) == -1
  792.       && TREE_INT_CST_HIGH (expr) == (1 << (prec - HOST_BITS_PER_INT)) - 1;
  793.   else
  794.     return TREE_INT_CST_LOW (expr) == (1 << prec) - 1;
  795. }
  796.  
  797. /* Return the length of a chain of nodes chained through TREE_CHAIN.
  798.    We expect a null pointer to mark the end of the chain.
  799.    This is the Lisp primitive `length'.  */
  800.  
  801. int
  802. list_length (t)
  803.      tree t;
  804. {
  805.   register tree tail;
  806.   register int len = 0;
  807.  
  808.   for (tail = t; tail; tail = TREE_CHAIN (tail))
  809.     len++;
  810.  
  811.   return len;
  812. }
  813.  
  814. /* Concatenate two chains of nodes (chained through TREE_CHAIN)
  815.    by modifying the last node in chain 1 to point to chain 2.
  816.    This is the Lisp primitive `nconc'.  */
  817.  
  818. tree
  819. chainon (op1, op2)
  820.      tree op1, op2;
  821. {
  822.   tree t;
  823.  
  824.   if (op1)
  825.     {
  826.       for (t = op1; TREE_CHAIN (t); t = TREE_CHAIN (t))
  827.     if (t == op2) abort ();    /* Circularity being created */
  828.       TREE_CHAIN (t) = op2;
  829.       return op1;
  830.     }
  831.   else return op2;
  832. }
  833.  
  834. /* Return a newly created TREE_LIST node whose
  835.    purpose and value fields are PARM and VALUE.  */
  836.  
  837. tree
  838. build_tree_list (parm, value)
  839.      tree parm, value;
  840. {
  841.   register tree t = make_node (TREE_LIST);
  842.   TREE_PURPOSE (t) = parm;
  843.   TREE_VALUE (t) = value;
  844.   return t;
  845. }
  846.  
  847. /* Return a newly created TREE_LIST node whose
  848.    purpose and value fields are PARM and VALUE
  849.    and whose TREE_CHAIN is CHAIN.  */
  850.  
  851. tree
  852. tree_cons (purpose, value, chain)
  853.      tree purpose, value, chain;
  854. {
  855.   register tree node = make_node (TREE_LIST);
  856.   TREE_CHAIN (node) = chain;
  857.   TREE_PURPOSE (node) = purpose;
  858.   TREE_VALUE (node) = value;
  859.   return node;
  860. }
  861.  
  862. /* Same as `tree_cons' but make a permanent object.  */
  863.  
  864. tree
  865. perm_tree_cons (purpose, value, chain)
  866.      tree purpose, value, chain;
  867. {
  868.   register tree node;
  869.   register struct obstack *ambient_obstack = current_obstack;
  870.   current_obstack = &permanent_obstack;
  871.  
  872.   node = make_node (TREE_LIST);
  873.   TREE_CHAIN (node) = chain;
  874.   TREE_PURPOSE (node) = purpose;
  875.   TREE_VALUE (node) = value;
  876.  
  877.   current_obstack = ambient_obstack;
  878.   return node;
  879. }
  880.  
  881. /* Same as `tree_cons', but make this node temporary, regardless.  */
  882.  
  883. tree
  884. temp_tree_cons (purpose, value, chain)
  885.      tree purpose, value, chain;
  886. {
  887.   register tree node;
  888.   register struct obstack *ambient_obstack = current_obstack;
  889.   current_obstack = &temporary_obstack;
  890.  
  891.   node = make_node (TREE_LIST);
  892.   TREE_CHAIN (node) = chain;
  893.   TREE_PURPOSE (node) = purpose;
  894.   TREE_VALUE (node) = value;
  895.  
  896.   current_obstack = ambient_obstack;
  897.   return node;
  898. }
  899.  
  900. /* Same as `tree_cons', but save this node if the function's RTL is saved.  */
  901.  
  902. tree
  903. saveable_tree_cons (purpose, value, chain)
  904.      tree purpose, value, chain;
  905. {
  906.   register tree node;
  907.   register struct obstack *ambient_obstack = current_obstack;
  908.   current_obstack = saveable_obstack;
  909.  
  910.   node = make_node (TREE_LIST);
  911.   TREE_CHAIN (node) = chain;
  912.   TREE_PURPOSE (node) = purpose;
  913.   TREE_VALUE (node) = value;
  914.  
  915.   current_obstack = ambient_obstack;
  916.   return node;
  917. }
  918.  
  919. /* Return the last node in a chain of nodes (chained through TREE_CHAIN).  */
  920.  
  921. tree
  922. tree_last (chain)
  923.      register tree chain;
  924. {
  925.   register tree next;
  926.   if (chain)
  927.     while (next = TREE_CHAIN (chain))
  928.       chain = next;
  929.   return chain;
  930. }
  931.  
  932. /* Reverse the order of elements in the chain T,
  933.    and return the new head of the chain (old last element).  */
  934.  
  935. tree
  936. nreverse (t)
  937.      tree t;
  938. {
  939.   register tree prev = 0, decl, next;
  940.   for (decl = t; decl; decl = next)
  941.     {
  942.       next = TREE_CHAIN (decl);
  943.       TREE_CHAIN (decl) = prev;
  944.       prev = decl;
  945.     }
  946.   return prev;
  947. }
  948.  
  949. /* Return the size nominally occupied by an object of type TYPE
  950.    when it resides in memory.  The value is measured in units of bytes,
  951.    and its data type is that normally used for type sizes
  952.    (which is the first type created by make_signed_type or
  953.    make_unsigned_type).  */
  954.  
  955. tree
  956. size_in_bytes (type)
  957.      tree type;
  958. {
  959.   if (type == error_mark_node)
  960.     return integer_zero_node;
  961.   type = TYPE_MAIN_VARIANT (type);
  962.   if (TYPE_SIZE (type) == 0)
  963.     {
  964.       incomplete_type_error (0, type);
  965.       return integer_zero_node;
  966.     }
  967.   return convert_units (TYPE_SIZE (type), TYPE_SIZE_UNIT (type),
  968.             BITS_PER_UNIT);
  969. }
  970.  
  971. /* Return the size of TYPE (in bytes) as an integer,
  972.    or return -1 if the size can vary.  */
  973.  
  974. int
  975. int_size_in_bytes (type)
  976.      tree type;
  977. {
  978.   int size;
  979.   if (type == error_mark_node)
  980.     return 0;
  981.   type = TYPE_MAIN_VARIANT (type);
  982.   if (TYPE_SIZE (type) == 0)
  983.     return -1;
  984.   if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  985.     return -1;
  986.   size = TREE_INT_CST_LOW (TYPE_SIZE (type)) * TYPE_SIZE_UNIT (type);
  987.   return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  988. }
  989.  
  990. /* Return, as an INTEGER_CST node, the number of elements for
  991.    TYPE (which is an ARRAY_TYPE).  */
  992.  
  993. tree
  994. array_type_nelts (type)
  995.      tree type;
  996. {
  997.   tree index_type = TYPE_DOMAIN (type);
  998.   return (tree_int_cst_equal (TYPE_MIN_VALUE (index_type), integer_zero_node)
  999.       ? TYPE_MAX_VALUE (index_type)
  1000.       : fold (build (MINUS_EXPR, integer_type_node,
  1001.              TYPE_MAX_VALUE (index_type),
  1002.              TYPE_MIN_VALUE (index_type))));
  1003. }
  1004.  
  1005. /* Return nonzero if arg is static -- a reference to an object in
  1006.    static storage.  This is not the same as the C meaning of `static'.  */
  1007.  
  1008. int
  1009. staticp (arg)
  1010.      tree arg;
  1011. {
  1012.   register enum tree_code code = TREE_CODE (arg);
  1013.  
  1014.   if ((code == VAR_DECL || code == FUNCTION_DECL || code == CONSTRUCTOR)
  1015.       && (TREE_STATIC (arg) || TREE_EXTERNAL (arg)))
  1016.     return 1;
  1017.  
  1018.   if (code == STRING_CST)
  1019.     return 1;
  1020.  
  1021.   if (code == COMPONENT_REF)
  1022.     return (DECL_VOFFSET (TREE_OPERAND (arg, 1)) == 0
  1023.         && staticp (TREE_OPERAND (arg, 0)));
  1024.  
  1025.   if (code == INDIRECT_REF)
  1026.     return TREE_LITERAL (TREE_OPERAND (arg, 0));
  1027.  
  1028.   if (code == ARRAY_REF)
  1029.     {
  1030.       if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
  1031.       && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
  1032.     return staticp (TREE_OPERAND (arg, 0));
  1033.     }
  1034.  
  1035.   return 0;
  1036. }
  1037.  
  1038. /* Return nonzero if REF is an lvalue valid for this language.
  1039.    Lvalues can be assigned, unless they have TREE_READONLY.
  1040.    Lvalues can have their address taken, unless they have TREE_REGDECL.  */
  1041.  
  1042. int
  1043. lvalue_p (ref)
  1044.      tree ref;
  1045. {
  1046.   register enum tree_code code = TREE_CODE (ref);
  1047.  
  1048.   if (language_lvalue_valid (ref))
  1049.     switch (code)
  1050.       {
  1051.       case COMPONENT_REF:
  1052.     return lvalue_p (TREE_OPERAND (ref, 0));
  1053.  
  1054.       case STRING_CST:
  1055.     return 1;
  1056.  
  1057.       case INDIRECT_REF:
  1058.       case ARRAY_REF:
  1059.       case VAR_DECL:
  1060.       case PARM_DECL:
  1061.       case RESULT_DECL:
  1062.       case ERROR_MARK:
  1063.     if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
  1064.         && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
  1065.       return 1;
  1066.     break;
  1067.  
  1068.       case NEW_EXPR:
  1069.     return 1;
  1070.  
  1071.       case CALL_EXPR:
  1072.     if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
  1073.       return 1;
  1074.       }
  1075.   return 0;
  1076. }
  1077.  
  1078. /* Return nonzero if REF is an lvalue valid for this language;
  1079.    otherwise, print an error message and return zero.  */
  1080.  
  1081. int
  1082. lvalue_or_else (ref, string)
  1083.      tree ref;
  1084.      char *string;
  1085. {
  1086.   int win = lvalue_p (ref);
  1087.   if (! win)
  1088.     error ("invalid lvalue in %s", string);
  1089.   return win;
  1090. }
  1091.  
  1092. /* This should be applied to any node which may be used in more than one place,
  1093.    but must be evaluated only once.  Normally, the code generator would
  1094.    reevaluate the node each time; this forces it to compute it once and save
  1095.    the result.  This is done by encapsulating the node in a SAVE_EXPR.  */
  1096.  
  1097. tree
  1098. save_expr (expr)
  1099.      tree expr;
  1100. {
  1101.   register tree t = fold (expr);
  1102.  
  1103.   /* If the tree evaluates to a constant, then we don't want to hide that
  1104.      fact (i.e. this allows further folding, and direct checks for constants).
  1105.      Since it is no problem to reevaluate literals, we just return the 
  1106.      literal node. */
  1107.  
  1108.   if (TREE_LITERAL (t) || TREE_READONLY (t) || TREE_CODE (t) == SAVE_EXPR)
  1109.     return t;
  1110.  
  1111.   return build (SAVE_EXPR, TREE_TYPE (expr), t, NULL);
  1112. }
  1113.  
  1114. /* Stabilize a reference so that we can use it any number of times
  1115.    without causing its operands to be evaluated more than once.
  1116.    Returns the stabilized reference.
  1117.  
  1118.    Also allows conversion expressions whose operands are references.
  1119.    Any other kind of expression is returned unchanged.  */
  1120.  
  1121. tree
  1122. stabilize_reference (ref)
  1123.      tree ref;
  1124. {
  1125.   register tree result;
  1126.   register enum tree_code code = TREE_CODE (ref);
  1127.  
  1128.   switch (code)
  1129.     {
  1130.     case VAR_DECL:
  1131.     case PARM_DECL:
  1132.     case RESULT_DECL:
  1133.       result = ref;
  1134.       break;
  1135.  
  1136.     case NOP_EXPR:
  1137.     case CONVERT_EXPR:
  1138.     case FLOAT_EXPR:
  1139.     case FIX_TRUNC_EXPR:
  1140.     case FIX_FLOOR_EXPR:
  1141.     case FIX_ROUND_EXPR:
  1142.     case FIX_CEIL_EXPR:
  1143.       result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
  1144.       break;
  1145.  
  1146.     case INDIRECT_REF:
  1147.       result = build_nt (INDIRECT_REF, save_expr (TREE_OPERAND (ref, 0)));
  1148.       break;
  1149.  
  1150.     case COMPONENT_REF:
  1151.       result = build_nt (COMPONENT_REF,
  1152.              stabilize_reference (TREE_OPERAND (ref, 0)),
  1153.              TREE_OPERAND (ref, 1));
  1154.       break;
  1155.  
  1156.     case ARRAY_REF:
  1157.       result = build_nt (ARRAY_REF, stabilize_reference (TREE_OPERAND (ref, 0)),
  1158.              save_expr (TREE_OPERAND (ref, 1)));
  1159.       break;
  1160.  
  1161.       /* If arg isn't a kind of lvalue we recognize, make no change.
  1162.      Caller should recognize the error for an invalid lvalue.  */
  1163.     default:
  1164.       return ref;
  1165.  
  1166.     case ERROR_MARK:
  1167.       return error_mark_node;
  1168.     }
  1169.  
  1170.   TREE_TYPE (result) = TREE_TYPE (ref);
  1171.   TREE_READONLY (result) = TREE_READONLY (ref);
  1172.   TREE_VOLATILE (result) = TREE_VOLATILE (ref);
  1173.   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
  1174.  
  1175.   return result;
  1176. }
  1177.  
  1178. /* Low-level constructors for expressions.  */
  1179.  
  1180. /* Build an expression of code CODE, data type TYPE,
  1181.    and operands as specified by the arguments ARG1 and following arguments.
  1182.    Expressions and reference nodes can be created this way.
  1183.    Constants, decls, types and misc nodes cannot be.  */
  1184.  
  1185. tree
  1186. build (va_alist)
  1187.      va_dcl
  1188. {
  1189.   register va_list p;
  1190.   enum tree_code code;
  1191.   register tree t;
  1192.   register int length;
  1193.   register int i;
  1194.  
  1195.   va_start (p);
  1196.  
  1197.   code = va_arg (p, enum tree_code);
  1198.   t = make_node (code);
  1199.   length = tree_code_length[(int) code];
  1200.   TREE_TYPE (t) = va_arg (p, tree);
  1201.  
  1202.   if (length == 2)
  1203.     {
  1204.       /* This is equivalent to the loop below, but faster.  */
  1205.       register tree arg0 = va_arg (p, tree);
  1206.       register tree arg1 = va_arg (p, tree);
  1207.       TREE_OPERAND (t, 0) = arg0;
  1208.       TREE_OPERAND (t, 1) = arg1;
  1209.       TREE_VOLATILE (t)
  1210.     = (arg0 && TREE_VOLATILE (arg0)) || (arg1 && TREE_VOLATILE (arg1));
  1211.     }
  1212.   else
  1213.     {
  1214.       for (i = 0; i < length; i++)
  1215.     {
  1216.       register tree operand = va_arg (p, tree);
  1217.       TREE_OPERAND (t, i) = operand;
  1218.       if (operand && TREE_VOLATILE (operand))
  1219.         TREE_VOLATILE (t) = 1;
  1220.     }
  1221.     }
  1222.   va_end (p);
  1223.   return t;
  1224. }
  1225.  
  1226. /* Similar except don't specify the TREE_TYPE
  1227.    and leave the TREE_VOLATILE as 0.
  1228.    It is permissible for arguments to be null,
  1229.    or even garbage if their values do not matter.  */
  1230.  
  1231. tree
  1232. build_nt (va_alist)
  1233.      va_dcl
  1234. {
  1235.   register va_list p;
  1236.   register enum tree_code code;
  1237.   register tree t;
  1238.   register int length;
  1239.   register int i;
  1240.  
  1241.   va_start (p);
  1242.  
  1243.   code = va_arg (p, enum tree_code);
  1244.   t = make_node (code);
  1245.   length = tree_code_length[(int) code];
  1246.  
  1247.   for (i = 0; i < length; i++)
  1248.     TREE_OPERAND (t, i) = va_arg (p, tree);
  1249.  
  1250.   va_end (p);
  1251.   return t;
  1252. }
  1253.  
  1254. tree
  1255. build_op_identifier (op1, op2)
  1256.      tree op1, op2;
  1257. {
  1258.   register tree t = make_node (OP_IDENTIFIER);
  1259.   TREE_PURPOSE (t) = op1;
  1260.   TREE_VALUE (t) = op2;
  1261.   return t;
  1262. }
  1263.  
  1264. /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
  1265.    We do NOT enter this node in any sort of symbol table.
  1266.  
  1267.    layout_decl is used to set up the decl's storage layout.
  1268.    Other slots are initialized to 0 or null pointers.  */
  1269.  
  1270. tree
  1271. build_decl (code, name, type)
  1272.      enum tree_code code;
  1273.      tree name, type;
  1274. {
  1275.   register tree t;
  1276.  
  1277.   t = make_node (code);
  1278.  
  1279. /*  if (type == error_mark_node)
  1280.     type = integer_type_node; */
  1281. /* That is not done, deliberately, so that having error_mark_node
  1282.    as the type can suppress useless errors in the use of this variable.  */
  1283.  
  1284.   DECL_NAME (t) = name;
  1285.   if (name)
  1286.     {
  1287.       DECL_PRINT_NAME (t) = IDENTIFIER_POINTER (name);
  1288.       DECL_ASSEMBLER_NAME (t) = IDENTIFIER_POINTER (name);
  1289.     }
  1290.   TREE_TYPE (t) = type;
  1291.   DECL_ARGUMENTS (t) = NULL_TREE;
  1292.   DECL_INITIAL (t) = NULL_TREE;
  1293.  
  1294.   if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
  1295.     layout_decl (t, 0);
  1296.   else if (code == FUNCTION_DECL)
  1297.     DECL_MODE (t) = FUNCTION_MODE;
  1298.  
  1299.   return t;
  1300. }
  1301.  
  1302. #if 0
  1303. /* Low-level constructors for statements.
  1304.    These constructors all expect source file name and line number
  1305.    as arguments, as well as enough arguments to fill in the data
  1306.    in the statement node.  */
  1307.  
  1308. tree
  1309. build_goto (filename, line, label)
  1310.      char *filename;
  1311.      int line;
  1312.      tree label;
  1313. {
  1314.   register tree t = make_node (GOTO_STMT);
  1315.   STMT_SOURCE_FILE (t) = filename;
  1316.   STMT_SOURCE_LINE (t) = line;
  1317.   STMT_BODY (t) = label;
  1318.   return t;
  1319. }
  1320.  
  1321. tree
  1322. build_return (filename, line, arg)
  1323.      char *filename;
  1324.      int line;
  1325.      tree arg;
  1326. {
  1327.   register tree t = make_node (RETURN_STMT);
  1328.  
  1329.   STMT_SOURCE_FILE (t) = filename;
  1330.   STMT_SOURCE_LINE (t) = line;
  1331.   STMT_BODY (t) = arg;
  1332.   return t;
  1333. }
  1334.  
  1335. tree
  1336. build_expr_stmt (filename, line, expr)
  1337.      char *filename;
  1338.      int line;
  1339.      tree expr;
  1340. {
  1341.   register tree t = make_node (EXPR_STMT);
  1342.  
  1343.   STMT_SOURCE_FILE (t) = filename;
  1344.   STMT_SOURCE_LINE (t) = line;
  1345.   STMT_BODY (t) = expr;
  1346.   return t;
  1347. }
  1348.  
  1349. tree
  1350. build_if (filename, line, cond, thenclause, elseclause)
  1351.      char *filename;
  1352.      int line;
  1353.      tree cond, thenclause, elseclause;
  1354. {
  1355.   register tree t = make_node (IF_STMT);
  1356.  
  1357.   STMT_SOURCE_FILE (t) = filename;
  1358.   STMT_SOURCE_LINE (t) = line;
  1359.   STMT_COND (t) = cond;
  1360.   STMT_THEN (t) = thenclause;
  1361.   STMT_ELSE (t) = elseclause;
  1362.   return t;
  1363. }
  1364.  
  1365. tree
  1366. build_exit (filename, line, cond)
  1367.      char *filename;
  1368.      int line;
  1369.      tree cond;
  1370. {
  1371.   register tree t = make_node (EXIT_STMT);
  1372.   STMT_SOURCE_FILE (t) = filename;
  1373.   STMT_SOURCE_LINE (t) = line;
  1374.   STMT_BODY (t) = cond;
  1375.   return t;
  1376. }
  1377.  
  1378. tree
  1379. build_asm_stmt (filename, line, asmcode)
  1380.      char *filename;
  1381.      int line;
  1382.      tree asmcode;
  1383. {
  1384.   register tree t = make_node (ASM_STMT);
  1385.   STMT_SOURCE_FILE (t) = filename;
  1386.   STMT_SOURCE_LINE (t) = line;
  1387.   STMT_BODY (t) = asmcode;
  1388.   return t;
  1389. }
  1390.  
  1391. tree
  1392. build_case (filename, line, object, cases)
  1393.      char *filename;
  1394.      int line;
  1395.      tree object, cases;
  1396. {
  1397.   register tree t = make_node (CASE_STMT);
  1398.   STMT_SOURCE_FILE (t) = filename;
  1399.   STMT_SOURCE_LINE (t) = line;
  1400.   STMT_CASE_INDEX (t) = object;
  1401.   STMT_CASE_LIST (t) = cases;
  1402.   return t;
  1403. }
  1404.  
  1405. tree
  1406. build_loop (filename, line, body)
  1407.      char *filename;
  1408.      int line;
  1409.      tree body;
  1410. {
  1411.   register tree t = make_node (LOOP_STMT);
  1412.   STMT_SOURCE_FILE (t) = filename;
  1413.   STMT_SOURCE_LINE (t) = line;
  1414.   STMT_BODY (t) = body;
  1415.   return t;
  1416. }
  1417.  
  1418. tree
  1419. build_compound (filename, line, body)
  1420.      char *filename;
  1421.      int line;
  1422.      tree body;
  1423. {
  1424.   register tree t = make_node (COMPOUND_STMT);
  1425.   STMT_SOURCE_FILE (t) = filename;
  1426.   STMT_SOURCE_LINE (t) = line;
  1427.   STMT_BODY (t) = body;
  1428.   return t;
  1429. }
  1430.  
  1431. #endif /* 0 */
  1432.  
  1433. /* LET_STMT nodes are used to represent the structure of binding contours
  1434.    and declarations, once those contours have been exited and their contents
  1435.    compiled.  This information is used for outputting debugging info.  */
  1436.  
  1437. tree
  1438. build_let (filename, line, vars, subblocks, supercontext, tags)
  1439.      char *filename;
  1440.      int line;
  1441.      tree vars, subblocks, supercontext, tags;
  1442. {
  1443.   register tree t = make_node (LET_STMT);
  1444.   STMT_SOURCE_FILE (t) = filename;
  1445.   STMT_SOURCE_LINE (t) = line;
  1446.   STMT_VARS (t) = vars;
  1447.   STMT_SUBBLOCKS (t) = subblocks;
  1448.   STMT_SUPERCONTEXT (t) = supercontext;
  1449.   STMT_BIND_SIZE (t) = 0;
  1450.   STMT_TYPE_TAGS (t) = tags;
  1451.   return t;
  1452. }
  1453.  
  1454. /* Return a type like TYPE except that its TREE_READONLY is CONSTP
  1455.    and its TREE_VOLATILE is VOLATILEP.
  1456.  
  1457.    Such variant types already made are recorded so that duplicates
  1458.    are not made.
  1459.  
  1460.    A variant types should never be used as the type of an expression.
  1461.    Always copy the variant information into the TREE_READONLY
  1462.    and TREE_VOLATILE of the expression, and then give the expression
  1463.    as its type the "main variant", the variant whose TREE_READONLY
  1464.    and TREE_VOLATILE are zero.  Use TYPE_MAIN_VARIANT to find the
  1465.    main variant.  */
  1466.  
  1467. tree
  1468. build_type_variant (type, constp, volatilep)
  1469.      tree type;
  1470.      int constp, volatilep;
  1471. {
  1472.   register tree t, m = TYPE_MAIN_VARIANT (type);
  1473.   register struct obstack *ambient_obstack = current_obstack;
  1474.  
  1475.   /* Treat any nonzero argument as 1.  */
  1476.   constp = !!constp;
  1477.   volatilep = !!volatilep;
  1478.  
  1479.   /* First search the chain variants for one that is what we want.  */
  1480.  
  1481.   for (t = m; t; t = TYPE_NEXT_VARIANT (t))
  1482.     if (constp == TREE_READONLY (t)
  1483.     && volatilep == TREE_VOLATILE (t))
  1484.       return t;
  1485.  
  1486.   /* We need a new one.  */
  1487.   current_obstack
  1488.     = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
  1489.  
  1490.   t = copy_node (type);
  1491.   TREE_READONLY (t) = constp;
  1492.   TREE_VOLATILE (t) = volatilep;
  1493.   TYPE_POINTER_TO (t) = 0;
  1494.   TYPE_REFERENCE_TO (t) = 0;
  1495.  
  1496.   /* Add this type to the chain of variants of TYPE.  */
  1497.   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
  1498.   TYPE_NEXT_VARIANT (m) = t;
  1499.  
  1500.   current_obstack = ambient_obstack;
  1501.   return t;
  1502. }
  1503.  
  1504. /* Hashing of types so that we don't make duplicates.
  1505.    The entry point is `type_hash_canon'.  */
  1506.  
  1507. /* Each hash table slot is a bucket containing a chain
  1508.    of these structures.  */
  1509.  
  1510. struct type_hash
  1511. {
  1512.   struct type_hash *next;    /* Next structure in the bucket.  */
  1513.   int hashcode;            /* Hash code of this type.  */
  1514.   tree type;            /* The type recorded here.  */
  1515. };
  1516.  
  1517. /* Now here is the hash table.  When recording a type, it is added
  1518.    to the slot whose index is the hash code mod the table size.
  1519.    Note that the hash table is used for several kinds of types
  1520.    (function types, array types and array index range types, for now).
  1521.    While all these live in the same table, they are completely independent,
  1522.    and the hash code is computed differently for each of these.  */
  1523.  
  1524. #define TYPE_HASH_SIZE 59
  1525. struct type_hash *type_hash_table[TYPE_HASH_SIZE];
  1526.  
  1527. /* Here is how primitive or already-canonicalized types' hash
  1528.    codes are made.  */
  1529. #define TYPE_HASH(TYPE) TREE_UID (TYPE)
  1530.  
  1531. /* Compute a hash code for a list of types (chain of TREE_LIST nodes
  1532.    with types in the TREE_VALUE slots), by adding the hash codes
  1533.    of the individual types.  */
  1534.  
  1535. int
  1536. type_hash_list (list)
  1537.      tree list;
  1538. {
  1539.   register int hashcode;
  1540.   register tree tail;
  1541.   for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
  1542.     hashcode += TYPE_HASH (TREE_VALUE (tail));
  1543.   return hashcode;
  1544. }
  1545.  
  1546. /* Look in the type hash table for a type isomorphic to TYPE.
  1547.    If one is found, return it.  Otherwise return 0.  */
  1548.  
  1549. tree
  1550. type_hash_lookup (hashcode, type)
  1551.      int hashcode;
  1552.      tree type;
  1553. {
  1554.   register struct type_hash *h;
  1555.   for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
  1556.     if (h->hashcode == hashcode
  1557.     && TREE_CODE (h->type) == TREE_CODE (type)
  1558.     && TREE_TYPE (h->type) == TREE_TYPE (type)
  1559.     && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
  1560.         || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
  1561.                    TYPE_MAX_VALUE (type)))
  1562.     && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
  1563.         || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
  1564.                    TYPE_MIN_VALUE (type)))
  1565.     && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
  1566.         || (TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
  1567.         && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
  1568.         && type_list_equal (TYPE_DOMAIN (h->type), TYPE_DOMAIN (type)))))
  1569.       return h->type;
  1570.   return 0;
  1571. }
  1572.  
  1573. /* Add an entry to the type-hash-table
  1574.    for a type TYPE whose hash code is HASHCODE.  */
  1575.  
  1576. void
  1577. type_hash_add (hashcode, type)
  1578.      int hashcode;
  1579.      tree type;
  1580. {
  1581.   register struct type_hash *h;
  1582.  
  1583.   h = (struct type_hash *) oballoc (sizeof (struct type_hash));
  1584.   h->hashcode = hashcode;
  1585.   h->type = type;
  1586.   h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
  1587.   type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
  1588. }
  1589.  
  1590. /* Given TYPE, and HASHCODE its hash code, return the canonical
  1591.    object for an identical type if one already exists.
  1592.    Otherwise, return TYPE, and record it as the canonical object
  1593.    if it is a permanent object.
  1594.  
  1595.    To use this function, first create a type of the sort you want.
  1596.    Then compute its hash code from the fields of the type that
  1597.    make it different from other similar types.
  1598.    Then call this function and use the value.
  1599.    This function frees the type you pass in if it is a duplicate.  */
  1600.  
  1601. /* Set to 1 to debug without canonicalization.  Never set by program.  */
  1602. int debug_no_type_hash = 0;
  1603.  
  1604. tree
  1605. type_hash_canon (hashcode, type)
  1606.      int hashcode;
  1607.      tree type;
  1608. {
  1609.   tree t1;
  1610.  
  1611.   if (debug_no_type_hash)
  1612.     return type;
  1613.  
  1614.   t1 = type_hash_lookup (hashcode, type);
  1615.   if (t1 != 0)
  1616.     {
  1617.       struct obstack *o
  1618.     = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
  1619.       obstack_free (o, type);
  1620.       return t1;
  1621.     }
  1622.  
  1623.   /* If this is a new type, record it for later reuse.  */
  1624.   if (current_obstack == &permanent_obstack)
  1625.     type_hash_add (hashcode, type);
  1626.  
  1627.   return type;
  1628. }
  1629.  
  1630. /* Given two lists of types
  1631.    (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
  1632.    return 1 if the lists contain the same types in the same order.
  1633.    Also, the TREE_PURPOSEs must match.  */
  1634.  
  1635. int
  1636. type_list_equal (l1, l2)
  1637.      tree l1, l2;
  1638. {
  1639.   register tree t1, t2;
  1640.   for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
  1641.     {
  1642.       if (TREE_VALUE (t1) != TREE_VALUE (t2))
  1643.     return 0;
  1644.       if (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
  1645.       && !simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
  1646.     return 0;
  1647.     }
  1648.  
  1649.   return t1 == t2;
  1650. }
  1651.  
  1652. /* Nonzero if integer constants T1 and T2
  1653.    represent the same constant value.  */
  1654.  
  1655. int
  1656. tree_int_cst_equal (t1, t2)
  1657.      tree t1, t2;
  1658. {
  1659.   if (t1 == t2)
  1660.     return 1;
  1661.   if (t1 == 0 || t2 == 0)
  1662.     return 0;
  1663.   if (TREE_CODE (t1) == INTEGER_CST
  1664.       && TREE_CODE (t2) == INTEGER_CST
  1665.       && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
  1666.       && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
  1667.     return 1;
  1668.   return 0;
  1669. }
  1670.  
  1671. /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
  1672.    The precise way of comparison depends on their data type.  */
  1673.  
  1674. int
  1675. tree_int_cst_lt (t1, t2)
  1676.      tree t1, t2;
  1677. {
  1678.   if (t1 == t2)
  1679.     return 0;
  1680.  
  1681.   if (!TREE_UNSIGNED (TREE_TYPE (t1)))
  1682.     return INT_CST_LT (t1, t2);
  1683.   return INT_CST_LT_UNSIGNED (t1, t2);
  1684. }
  1685.  
  1686. /* Compare two constructor-element-type constants.  */
  1687.  
  1688. int
  1689. simple_cst_equal (t1, t2)
  1690.      tree t1, t2;
  1691. {
  1692.   register enum tree_code code1, code2;
  1693.  
  1694.   if (t1 == t2)
  1695.     return 1;
  1696.   if (t1 == 0 || t2 == 0)
  1697.     return 0;
  1698.  
  1699.   code1 = TREE_CODE (t1);
  1700.   code2 = TREE_CODE (t2);
  1701.  
  1702.   if (code1 == NOP_EXPR || code1 == CONVERT_EXPR)
  1703.     if (code2 == NOP_EXPR || code2 == CONVERT_EXPR)
  1704.       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  1705.     else
  1706.       return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
  1707.   else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR)
  1708.     return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
  1709.  
  1710.   if (code1 != code2)
  1711.     return 0;
  1712.  
  1713.   switch (code1)
  1714.     {
  1715.     case INTEGER_CST:
  1716.       return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
  1717.     && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
  1718.  
  1719.     case REAL_CST:
  1720.       return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
  1721.  
  1722.     case STRING_CST:
  1723.       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
  1724.     && !strcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2));
  1725.  
  1726.     case CONSTRUCTOR:
  1727.       abort ();
  1728.  
  1729.     case VAR_DECL:
  1730.     case PARM_DECL:
  1731.     case CONST_DECL:
  1732.       return 0;
  1733.  
  1734.     case PLUS_EXPR:
  1735.     case MINUS_EXPR:
  1736.     case MULT_EXPR:
  1737.     case TRUNC_DIV_EXPR:
  1738.     case TRUNC_MOD_EXPR:
  1739.     case LSHIFT_EXPR:
  1740.     case RSHIFT_EXPR:
  1741.       return (simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
  1742.           && simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
  1743.  
  1744.     case NEGATE_EXPR:
  1745.     case ADDR_EXPR:
  1746.     case REFERENCE_EXPR:
  1747.     case INDIRECT_REF:
  1748.       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  1749.  
  1750.     default:
  1751.       abort ();
  1752.     }
  1753. }
  1754.  
  1755. /* Constructors for pointer, array and function types.
  1756.    (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
  1757.    constructed by language-dependent code, not here.)  */
  1758.  
  1759. /* Construct, lay out and return the type of pointers to TO_TYPE.
  1760.    If such a type has already been constructed, reuse it.  */
  1761.  
  1762. tree
  1763. build_pointer_type (to_type)
  1764.      tree to_type;
  1765. {
  1766.   register tree t = TYPE_POINTER_TO (to_type);
  1767.   register struct obstack *ambient_obstack = current_obstack;
  1768.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  1769.  
  1770.   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
  1771.  
  1772.   if (t)
  1773.     return t;
  1774.  
  1775.   /* We need a new one.  If TO_TYPE is permanent, make this permanent too.  */
  1776.   if (TREE_PERMANENT (to_type))
  1777.     {
  1778.       current_obstack = &permanent_obstack;
  1779.       saveable_obstack = &permanent_obstack;
  1780.     }
  1781.  
  1782.   t = make_node (POINTER_TYPE);
  1783.   TREE_TYPE (t) = to_type;
  1784.  
  1785.   /* Record this type as the pointer to TO_TYPE.  */
  1786.   TYPE_POINTER_TO (to_type) = t;
  1787.  
  1788.   /* Lay out the type.  This function has many callers that are concerned
  1789.      with expression-construction, and this simplifies them all.
  1790.      Also, it guarantees the TYPE_SIZE is permanent if the type is.  */
  1791.   layout_type (t);
  1792.  
  1793.   current_obstack = ambient_obstack;
  1794.   saveable_obstack = ambient_saveable_obstack;
  1795.   return t;
  1796. }
  1797.  
  1798. /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
  1799.    MAXVAL should be the maximum value in the domain
  1800.    (one less than the length of the array).  */
  1801.  
  1802. tree
  1803. build_index_type (maxval)
  1804.      tree maxval;
  1805. {
  1806.   register tree itype = make_node (INTEGER_TYPE);
  1807.   int maxint = TREE_INT_CST_LOW (maxval);
  1808.   TYPE_PRECISION (itype) = BITS_PER_WORD;
  1809.   TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
  1810.   TREE_TYPE (TYPE_MIN_VALUE (itype)) = sizetype;
  1811.   TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
  1812.   TYPE_MODE (itype) = SImode;
  1813.   TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
  1814.   TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
  1815.   TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
  1816.   return type_hash_canon (maxint > 0 ? maxint : - maxint, itype);
  1817. }
  1818.  
  1819. /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
  1820.    and number of elements specified by the range of values of INDEX_TYPE.
  1821.    If such a type has already been constructed, reuse it.  */
  1822.  
  1823. tree
  1824. build_array_type (elt_type, index_type)
  1825.      tree elt_type, index_type;
  1826. {
  1827.   register tree t = make_node (ARRAY_TYPE);
  1828.   int hashcode;
  1829.  
  1830.   if (TREE_CODE (elt_type) == FUNCTION_TYPE)
  1831.     {
  1832.       error ("arrays of functions are not meaningful");
  1833.       elt_type = integer_type_node;
  1834.     }
  1835.  
  1836.   TREE_TYPE (t) = elt_type;
  1837.   TYPE_DOMAIN (t) = index_type;
  1838.  
  1839.   /* Make sure TYPE_POINTER_TO (elt_type) is filled in.  */
  1840.   build_pointer_type (elt_type);
  1841.  
  1842.   if (index_type == 0)
  1843.     return t;
  1844.  
  1845.   hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
  1846.   t = type_hash_canon (hashcode, t);
  1847.  
  1848.   if (TYPE_SIZE (t) == 0)
  1849.     layout_type (t);
  1850.   return t;
  1851. }
  1852.  
  1853. /* Construct, lay out and return
  1854.    the type of functions returning type VALUE_TYPE
  1855.    given arguments of types ARG_TYPES.
  1856.    ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
  1857.    are data type nodes for the arguments of the function.
  1858.    If such a type has already been constructed, reuse it.  */
  1859.  
  1860. tree
  1861. build_function_type (value_type, arg_types)
  1862.      tree value_type, arg_types;
  1863. {
  1864.   register tree t;
  1865.   int hashcode;
  1866.  
  1867.   if (TREE_CODE (value_type) == FUNCTION_TYPE
  1868.       || TREE_CODE (value_type) == ARRAY_TYPE)
  1869.     {
  1870.       error ("function return type cannot be function or array");
  1871.       value_type = integer_type_node;
  1872.     }
  1873.  
  1874.   /* Make a node of the sort we want.  */
  1875.   t = make_node (FUNCTION_TYPE);
  1876.   TREE_TYPE (t) = value_type;
  1877.   TYPE_ARG_TYPES (t) = arg_types;
  1878.  
  1879.   /* If we already have such a type, use the old one and free this one.  */
  1880.   hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
  1881.   t = type_hash_canon (hashcode, t);
  1882.  
  1883.   if (TYPE_SIZE (t) == 0)
  1884.     layout_type (t);
  1885.   return t;
  1886. }
  1887.  
  1888. /* Build the node for the type of references-to-TO_TYPE.  */
  1889.  
  1890. tree
  1891. build_reference_type (to_type)
  1892.      tree to_type;
  1893. {
  1894.   register tree t = TYPE_REFERENCE_TO (to_type);
  1895.   register struct obstack *ambient_obstack = current_obstack;
  1896.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  1897.  
  1898.   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
  1899.  
  1900.   if (t)
  1901.     return t;
  1902.  
  1903.   /* We need a new one.  If TO_TYPE is permanent, make this permanent too.  */
  1904.   if (TREE_PERMANENT (to_type))
  1905.     {
  1906.       current_obstack = &permanent_obstack;
  1907.       saveable_obstack = &permanent_obstack;
  1908.     }
  1909.  
  1910.   t = make_node (REFERENCE_TYPE);
  1911.   TREE_TYPE (t) = to_type;
  1912.  
  1913.   /* Record this type as the pointer to TO_TYPE.  */
  1914.   TYPE_REFERENCE_TO (to_type) = t;
  1915.  
  1916.   layout_type (t);
  1917.  
  1918.   current_obstack = ambient_obstack;
  1919.   saveable_obstack = ambient_saveable_obstack;
  1920.   return t;
  1921. }
  1922.  
  1923. /* Construct, lay out and return the type of methods belonging to class
  1924.    BASETYPE and whose arguments and values are described by TYPE.
  1925.    If that type exists already, reuse it.
  1926.    TYPE must be a FUNCTION_TYPE node.  */
  1927.  
  1928. tree
  1929. build_method_type (basetype, type)
  1930.      tree basetype, type;
  1931. {
  1932.   register tree t;
  1933.   int hashcode;
  1934.  
  1935.   /* Make a node of the sort we want.  */
  1936.   t = make_node (METHOD_TYPE);
  1937.  
  1938.   if (TREE_CODE (type) != FUNCTION_TYPE)
  1939.     abort ();
  1940.  
  1941.   TYPE_METHOD_BASETYPE (t) = basetype;
  1942.   TREE_TYPE (t) = TREE_TYPE (type);
  1943.  
  1944.   /* The actual arglist for this function includes a "hidden" argument
  1945.      which is "this".  Put it into the list of argument types.  */
  1946.  
  1947.   TYPE_ARG_TYPES (t)
  1948.     = tree_cons (NULL, build_pointer_type (basetype), TYPE_ARG_TYPES (type));
  1949.  
  1950.   /* If we already have such a type, use the old one and free this one.  */
  1951.   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
  1952.   t = type_hash_canon (hashcode, t);
  1953.  
  1954.   if (TYPE_SIZE (t) == 0)
  1955.     layout_type (t);
  1956.  
  1957.   return t;
  1958. }
  1959.  
  1960. /* Construct, lay out and return the type of methods belonging to class
  1961.    BASETYPE and whose arguments and values are described by TYPE.
  1962.    If that type exists already, reuse it.
  1963.    TYPE must be a FUNCTION_TYPE node.  */
  1964.  
  1965. tree
  1966. build_offset_type (basetype, type)
  1967.      tree basetype, type;
  1968. {
  1969.   register tree t;
  1970.   int hashcode;
  1971.  
  1972.   /* Make a node of the sort we want.  */
  1973.   t = make_node (OFFSET_TYPE);
  1974.  
  1975.   TYPE_OFFSET_BASETYPE (t) = basetype;
  1976.   TREE_TYPE (t) = type;
  1977.  
  1978.   /* If we already have such a type, use the old one and free this one.  */
  1979.   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
  1980.   t = type_hash_canon (hashcode, t);
  1981.  
  1982.   if (TYPE_SIZE (t) == 0)
  1983.     layout_type (t);
  1984.  
  1985.   return t;
  1986. }
  1987.  
  1988. /* Return OP, stripped of any conversions to wider types as much as is safe.
  1989.    Converting the value back to OP's type makes a value equivalent to OP.
  1990.  
  1991.    If FOR_TYPE is nonzero, we return a value which, if converted to
  1992.    type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
  1993.  
  1994.    If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
  1995.    narrowest type that can hold the value, even if they don't exactly fit.
  1996.    Otherwise, bit-field references are changed to a narrower type
  1997.    only if they can be fetched directly from memory in that type.
  1998.  
  1999.    OP must have integer, real or enumeral type.  Pointers are not allowed!
  2000.  
  2001.    There are some cases where the obvious value we could return
  2002.    would regenerate to OP if converted to OP's type, 
  2003.    but would not extend like OP to wider types.
  2004.    If FOR_TYPE indicates such extension is contemplated, we eschew such values.
  2005.    For example, if OP is (unsigned short)(signed char)-1,
  2006.    we avoid returning (signed char)-1 if FOR_TYPE is int,
  2007.    even though extending that to an unsigned short would regenerate OP,
  2008.    since the result of extending (signed char)-1 to (int)
  2009.    is different from (int) OP.  */
  2010.  
  2011. tree
  2012. get_unwidened (op, for_type)
  2013.      register tree op;
  2014.      tree for_type;
  2015. {
  2016.   /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension.  */
  2017.   /* TYPE_PRECISION is safe in place of type_precision since
  2018.      pointer types are not allowed.  */
  2019.   register tree type = TREE_TYPE (op);
  2020.   register int final_prec = TYPE_PRECISION (for_type != 0 ? for_type : type);
  2021.   register int uns
  2022.     = (for_type != 0 && for_type != type
  2023.        && final_prec > TYPE_PRECISION (type)
  2024.        && TREE_UNSIGNED (type));
  2025.   register tree win = op;
  2026.  
  2027.   while (TREE_CODE (op) == NOP_EXPR)
  2028.     {
  2029.       register int bitschange
  2030.     = TYPE_PRECISION (TREE_TYPE (op))
  2031.       - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
  2032.  
  2033.       /* Truncations are many-one so cannot be removed.
  2034.      Unless we are later going to truncate down even farther.  */
  2035.       if (bitschange < 0
  2036.       && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
  2037.     break;
  2038.  
  2039.       /* See what's inside this conversion.  If we decide to strip it,
  2040.      we will set WIN.  */
  2041.       op = TREE_OPERAND (op, 0);
  2042.  
  2043.       /* If we have not stripped any zero-extensions (uns is 0),
  2044.      we can strip any kind of extension.
  2045.      If we have previously stripped a zero-extension,
  2046.      only zero-extensions can safely be stripped.
  2047.      Any extension can be stripped if the bits it would produce
  2048.      are all going to be discarded later by truncating to FOR_TYPE.  */
  2049.  
  2050.       if (bitschange > 0)
  2051.     {
  2052.       if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
  2053.         win = op;
  2054.       /* TREE_UNSIGNED says whether this is a zero-extension.
  2055.          Let's avoid computing it if it does not affect WIN
  2056.          and if UNS will not be needed again.  */
  2057.       if ((uns || TREE_CODE (op) == NOP_EXPR)
  2058.           && TREE_UNSIGNED (TREE_TYPE (op)))
  2059.         {
  2060.           uns = 1;
  2061.           win = op;
  2062.         }
  2063.     }
  2064.     }
  2065.  
  2066.   if (TREE_CODE (op) == COMPONENT_REF
  2067.       /* Since type_for_size always gives an integer type.  */
  2068.       && TREE_CODE (type) != REAL_TYPE)
  2069.     {
  2070.       int innerprec = (TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)))
  2071.                * DECL_SIZE_UNIT (TREE_OPERAND (op, 1)));
  2072.       type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
  2073.  
  2074.       /* We can get this structure field in the narrowest type it fits in.
  2075.      If FOR_TYPE is 0, do this only for a field that matches the
  2076.      narrower type exactly and is aligned for it (i.e. mode isn't BI).
  2077.      The resulting extension to its nominal type (a fullword type)
  2078.      must fit the same conditions as for other extensions.  */
  2079.  
  2080.       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
  2081.       && (for_type || DECL_MODE (TREE_OPERAND (op, 1)) != BImode)
  2082.       && (! uns || final_prec <= innerprec
  2083.           || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
  2084.       && type != 0)
  2085.     {
  2086.       win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
  2087.                TREE_OPERAND (op, 1));
  2088.       TREE_VOLATILE (win) = TREE_VOLATILE (op);
  2089.       TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
  2090.     }
  2091.     }
  2092.   return win;
  2093. }
  2094.  
  2095. /* Return OP or a simpler expression for a narrower value
  2096.    which can be sign-extended or zero-extended to give back OP.
  2097.    Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
  2098.    or 0 if the value should be sign-extended.  */
  2099.  
  2100. tree
  2101. get_narrower (op, unsignedp_ptr)
  2102.      register tree op;
  2103.      int *unsignedp_ptr;
  2104. {
  2105.   register int uns = 0;
  2106.   int first = 1;
  2107.   register tree win = op;
  2108.  
  2109.   while (TREE_CODE (op) == NOP_EXPR)
  2110.     {
  2111.       register int bitschange
  2112.     = TYPE_PRECISION (TREE_TYPE (op))
  2113.       - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
  2114.  
  2115.       /* Truncations are many-one so cannot be removed.  */
  2116.       if (bitschange < 0)
  2117.     break;
  2118.  
  2119.       /* See what's inside this conversion.  If we decide to strip it,
  2120.      we will set WIN.  */
  2121.       op = TREE_OPERAND (op, 0);
  2122.  
  2123.       if (bitschange > 0)
  2124.     {
  2125.       /* An extension: the outermost one can be stripped,
  2126.          but remember whether it is zero or sign extension.  */
  2127.       if (first)
  2128.         uns = TREE_UNSIGNED (TREE_TYPE (op));
  2129.       /* Otherwise, if a sign extension has been stripped,
  2130.          only sign extensions can now be stripped;
  2131.          if a zero extension has been stripped, only zero-extensions.  */
  2132.       else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
  2133.         break;
  2134.       first = 0;
  2135.     }
  2136.       /* A change in nominal type can always be stripped.  */
  2137.  
  2138.       win = op;
  2139.     }
  2140.  
  2141.   if (TREE_CODE (op) == COMPONENT_REF
  2142.       /* Since type_for_size always gives an integer type.  */
  2143.       && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
  2144.     {
  2145.       int innerprec = (TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)))
  2146.                * DECL_SIZE_UNIT (TREE_OPERAND (op, 1)));
  2147.       tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
  2148.  
  2149.       /* We can get this structure field in a narrower type that fits it,
  2150.      but the resulting extension to its nominal type (a fullword type)
  2151.      must satisfy the same conditions as for other extensions.
  2152.  
  2153.      Do this only for fields that are aligned (not BImode),
  2154.      because when bit-field insns will be used there is no
  2155.      advantage in doing this.  */
  2156.  
  2157.       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
  2158.       && DECL_MODE (TREE_OPERAND (op, 1)) != BImode
  2159.       && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
  2160.       && type != 0)
  2161.     {
  2162.       if (first)
  2163.         uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
  2164.       win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
  2165.                TREE_OPERAND (op, 1));
  2166.       TREE_VOLATILE (win) = TREE_VOLATILE (op);
  2167.       TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
  2168.     }
  2169.     }
  2170.   *unsignedp_ptr = uns;
  2171.   return win;
  2172. }
  2173.  
  2174. /* Return the precision of a type, for arithmetic purposes.
  2175.    Supports all types on which arithmetic is possible
  2176.    (including pointer types).
  2177.    It's not clear yet what will be right for complex types.  */
  2178.  
  2179. int
  2180. type_precision (type)
  2181.      register tree type;
  2182. {
  2183.   return ((TREE_CODE (type) == INTEGER_TYPE
  2184.        || TREE_CODE (type) == ENUMERAL_TYPE
  2185.        || TREE_CODE (type) == REAL_TYPE)
  2186.       ? TYPE_PRECISION (type) : POINTER_SIZE);
  2187. }
  2188.  
  2189. /* Nonzero if integer constant C has a value that is permissible
  2190.    for type TYPE (an INTEGER_TYPE).  */
  2191.  
  2192. int
  2193. int_fits_type_p (c, type)
  2194.      tree c, type;
  2195. {
  2196.   if (TREE_UNSIGNED (type))
  2197.     return (!INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c)
  2198.         && !INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type)));
  2199.   else
  2200.     return (!INT_CST_LT (TYPE_MAX_VALUE (type), c)
  2201.         && !INT_CST_LT (c, TYPE_MIN_VALUE (type)));
  2202. }
  2203.